<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>AI语音助手设置</title>
  <link rel="stylesheet" href="/app/admin/component/pear/css/pear.css" />
  <link rel="stylesheet" href="/app/admin/admin/css/reset.css" />
</head>
<body class="pear-container">

<div class="layui-card">
  <div class="layui-card-body">

    <div class="layui-tab layui-tab-brief">
      <ul class="layui-tab-title">
        <li class="layui-this">移动H5设置</li>
        <?=$voice_mini ?>
        <li>语音听写</li>
        <li>语音朗读</li>
        <li>微信服务商支付</li>
      </ul>

      <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
          <form class="layui-form" lay-filter="setting" onsubmit="return false">
            <div class="layui-form-item">
              <label class="layui-form-label">站点名称</label>
              <div class="layui-input-inline">
                <input type="text" name="site_name" placeholder="" autocomplete="off" class="layui-input">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">首页打字文本</label>
              <div class="layui-input-inline">
                <textarea name="run_words" placeholder="打字文本，一行一个" style="width:14em;height:14em;" class="layui-textarea"></textarea>
              </div>
            </div>
             <div class="layui-form-item">
              <label class="layui-form-label">开启Redis</label>
              <div class="layui-input-inline">
                <input type="checkbox" name="redis_enable" id="redis_enable" lay-skin="switch">
              </div>
              <div class="layui-form-mid layui-font-orange">如果关闭登录验证码存mysql</div>
            </div>
            <div class="layui-form-item">
              <div class="layui-input-block">
                <button class="pear-btn pear-btn-primary" lay-submit="" lay-filter="setting">保 存</button>
              </div>
            </div>
          </form>
        </div>
        
        
        <!-- 小程序 -->
        <?=$mini_setting?>
        
        <!-- 语音设置 -->
        <div class="layui-tab-item">
          <form class="layui-form" lay-filter="setting" onsubmit="return false">
            <div class="layui-form-item">
              <label class="layui-form-label">讯飞AppID</label>
              <div class="layui-input-inline">
                <input type="text" name="xunfei_iat_appid" required  lay-verify="required" autocomplete="off" class="layui-input">
              </div>
               <div class="layui-form-mid layui-font-orange">
                <a href="https://www.xfyun.cn/services/voicedictation" target="_blank">点击打开讯飞语音识别官网</a>
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">讯飞SecretKey</label>
              <div class="layui-input-inline">
                <input type="text" name="xunfei_iat_secret_key" required  lay-verify="required" autocomplete="off" class="layui-input">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">讯飞ApiKey</label>
              <div class="layui-input-inline">
                <input type="text" name="xunfei_iat_apikey" required  lay-verify="required" autocomplete="off" class="layui-input">
              </div>
            </div>
             <div class="layui-form-item">
              <label class="layui-form-label">延时识别</label>
              <div class="layui-input-inline">
                <input type="text" name="vad_eos" autocomplete="off" class="layui-input" placeholder="默认2000，多少毫秒检测不到说话，系统就认为这轮讲完了">
              </div>
              <div class="layui-form-mid layui-font-orange">多长时间没有接收到语音信息识别结束，单位毫秒</div>
            </div>
            
            <div class="layui-form-item">
              <div class="layui-input-block">
                <button class="pear-btn pear-btn-primary" lay-submit="" lay-filter="setting">保 存</button>
              </div>
            </div>
          </form>
        </div>
        
        
         <!-- 朗读设置 -->
        <div class="layui-tab-item">
          <form class="layui-form" lay-filter="setting" onsubmit="return false">
            <div class="layui-form-item">
              <label class="layui-form-label">GPT KEY</label>
              <div class="layui-input-inline">
                <input type="text" name="gpt_api_key" required  lay-verify="required" autocomplete="off" class="layui-input">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">接口地址</label>
              <div class="layui-input-inline">
                <input type="text" name="gpt_api_host" required  lay-verify="required" autocomplete="off" class="layui-input">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">开启莹莹朗读</label>
              <div class="layui-input-inline">
                <input type="checkbox" name="yingying_enable" id="yingying_enable" lay-skin="switch">
              </div>
              <div class="layui-form-mid layui-font-orange">莹莹朗读免费</div>
            </div>
            <div class="layui-form-item">
              <div class="layui-input-block">
                <button class="pear-btn pear-btn-primary" lay-submit="" lay-filter="setting">保 存</button>
              </div>
            </div>
          </form>
        </div>
        
         <!--支付配置-->
        <div class="layui-tab-item">
          <form class="layui-form" lay-filter="setting" onsubmit="return false">
             <div class="layui-form-item">
              <label class="layui-form-label">商户号</label>
              <div class="layui-input-inline">
                <input type="text" name="sub_mch_id" required  lay-verify="required" autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-font-orange">联系QQ41518265开通,费率0.38%</div>
            </div>
             <div class="layui-form-item">
              <label class="layui-form-label">接口地址</label>
              <div class="layui-input-inline">
                <input type="text" name="unifiedorder_host" required  lay-verify="required" autocomplete="off" class="layui-input" style="width:300px;">
              </div>
              <div class="layui-form-mid layui-font-orange"></div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">回调域名</label>
              <div class="layui-input-inline">
                <input type="text" name="notify_host" required  lay-verify="required" autocomplete="off" class="layui-input" style="width:300px;">
              </div>
            </div>
            <div class="layui-form-item">
              <div class="layui-input-block">
                <button class="pear-btn pear-btn-primary" lay-submit="" lay-filter="setting">保 存</button>
              </div>
            </div>
          </form>
        </div>
        
        
      </div>
    </div>
  </div>
</div>


<script src="/app/admin/component/layui/layui.js"></script>
<script src="/app/admin/component/pear/pear.js"></script>
<script src="/app/admin/admin/js/permission.js"></script>
<script src="/app/admin/admin/js/common.js"></script>


<style>
  .layui-form-label {
    width: 100px;
  }
</style>

<script>
  layui.use(["form", "popup"], function(){
    let form = layui.form;
    let $ = layui.jquery;
    
    // 基础配置
    $.ajax({
      url: "/app/voice/admin/setting/select",
      success: function (res) {
        if (res.code) {
          return layui.popup.failure(res.msg);
        }
        for (let name in res.data) {
            var inputElement = document.querySelector('input[name="' + name + '"]');
            if (inputElement) {
                inputElement.value = res.data[name];
                if(name=='yingying_enable'){
                    inputElement.checked = res.data[name];
                    form.render('checkbox');
                }
                if(name=='redis_enable'){
                    inputElement.checked = res.data[name];
                    form.render('checkbox');
                }
            }
            var inputElement = document.querySelector('textarea[name="' + name + '"]');
            if (inputElement) {
                inputElement.value = res.data[name];
            }
            form.on("submit(setting)", function(data){
                if(data.field.gpt_api_key){
                    if(document.getElementById("yingying_enable").checked){
                        data.field.yingying_enable = 1
                    }else{
                        data.field.yingying_enable = 0
                    }
                }
                if(data.field.site_name){
                    if(document.getElementById("redis_enable").checked){
                        data.field.redis_enable = 1
                    }else{
                        data.field.redis_enable = 0
                    }
                }
                $.ajax({
                    url: "/app/voice/admin/setting/update",
                    dataType: "json",
                    type: "POST",
                    data: data.field,
                    success: function (res) {
                    console.log('aaa',data.field)
                    form.render('checkbox');
                    console.log('bb',document.getElementById("yingying_enable").checked)
                    if (res.code) {
                        return layui.popup.failure(res.msg);
                    }
                        return layui.popup.success("操作成功");
                    }
                });
                return false;
            });
        }
      }
    });
    
});
</script>
</body>
</html>

